package com.mtsmda.bookjava7.chapter2.castingEx;

public class Run {

	public static void main(String[] args) {
		// downcast
		Animal animal = new Animal();
		animal.animal();
		animal.eat();
		// ((Dog)animal).dog();//java.lang.ClassCastException

		Eatable eatable = new Animal();
		eatable.eat();
		((Animal) eatable).animal();
		// ((Dog)eatable).animal();//java.lang.ClassCastException

		Dog dog = new Dog();
		// Dog dog2 = (Animal) animal;
		/*
		 * java.lang.Error: Unresolved compilation problem: Type mismatch:
		 * cannot convert from Animal to Dog
		 */
		// Dog dog2 = (Dog) animal; // java.lang.ClassCastException
		// String strAnimal = (String) animal;//Cannot cast from Animal to
		// String
		Animal animal2 = dog;
		animal2.animal();

		Animal animalDog = new Dog();
		animalDog.animal();
		animalDog.eat();
		((Dog) animalDog).dog();

		Eatable eatableDog = new Dog();
		eatableDog.eat();
		((Dog) eatableDog).dog();
		((Dog) eatableDog).animal();
		Eatable eatable2 = new Eatable() {
			@Override
			public void eat() {
				System.out.println("inner");
			}
		};

		eatable2.eat();
		
		animal.getAnimal();
		animal.getDog().eat();

	}

}